package com.example.testservicce;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.example.testservicce.service.MyService;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btnStart= (Button) findViewById(R.id.btn_start);
        Button btnStop= (Button) findViewById(R.id.btn_stop);
        btnStart.setOnClickListener(this);
        btnStop.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if(v.getId()==R.id.btn_start){
            Intent intent=new Intent(getApplicationContext(), MyService.class);
            startService(intent);
        }else{
            Intent intent=new Intent(getApplicationContext(), MyService.class);
            stopService(intent);
        }
    }
}
